package challenges;

import game.Challenge;
import gfx.Shapes;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.PointF;

public class Snowfall extends Challenge {
	// 0 is Freezing, nothing happens.  Negative means snow, higher negative, more snowfall.
	// Positive is warm.  Higher means faster melting.
	private short weather;
	private Treeline trees;
	
	public Snowfall(){
		trees = new Treeline();
	}
	
	public void draw(GL10 gl){
		drawBG(gl);
		drawSky(gl);
		drawGround(gl);
		
		super.draw(gl);
	}
	public void drawGround(GL10 gl){
		Shapes.drawSquare(gl, 5, 1.5f, 5, 1.5f, 0, .4f, 0, 1);
	}
	public void drawSky(GL10 gl){
//		Shapes.drawSquare(gl, 5, 3, 5, 3, 1, 1, 1, .35f);
		gl.glPushMatrix();
//		gl.glTranslatef(5, 0, 0);
		gl.glRotatef(-90, 0, 0, 1);
		Shapes.drawHorizontalGradiantSquare(gl, 0, 0, 10, 10, 0, 0, 0, .55f, .5f, .5f, .5f, .45f);
		gl.glPopMatrix();
	}
	public void drawBG(GL10 gl){
		Shapes.drawSquare(gl, 5, 3, 5, 3, .5f, .5f, .5f, 1);
		trees.draw(gl);
	}
	
	public void update(long time){
		
	}
	
	public boolean handleUp(PointF location) {
		if(super.handleUp(location))
			return false;
		return true;
	}

	public boolean handleDrag(PointF location) {
		if(super.handleDrag(location))
			return false;
		return true;
	}

	public boolean handleTouch(PointF location) {
		if(super.handleTouch(location))
			return false;
		return true;
	}
	
	private void reset(){
	}
	
	class SnowfallManager{
		private Snowflake[] flakes;
		private short flakeCount;
		private short updateIterator, drawIterator;
		
		public SnowfallManager(){
			flakes = new Snowflake[flakeCount];
			for(int i = 0; i < flakeCount; ++i)
				flakes[i] = new Snowflake();
		}
		
		public void draw(GL10 gl){
			for(drawIterator = 0; drawIterator < flakeCount; ++drawIterator)
				flakes[drawIterator].draw(gl);
		}
		public void update(long time){
			for(updateIterator = 0; updateIterator < flakeCount; ++updateIterator)
				flakes[updateIterator].update(time);
		}
		
		class Snowflake{
			private float x, y;
			private byte depth;
			
			public Snowflake(){
				
			}
			
			public void draw(GL10 gl){
				
			}
			public void update(long time){
				
			}
		}
	}
	
	class Treeline{
		private short treeCount = 44;
		private float maxTreeHeight = .25f;
		private float minTreeHeight = .1f;
		private short updateIterator, drawIterator;
		
		private Tree[] trees;
		
		public Treeline(){
			trees = new Tree[treeCount];
			for(int i = 0; i < treeCount; ++i)
				trees[i] = new Tree(i / 4f, (float) (Math.random() * (maxTreeHeight - minTreeHeight) + minTreeHeight));
		}
		public void draw(GL10 gl){
			for(drawIterator = 0; drawIterator < treeCount; ++drawIterator)
				trees[drawIterator].draw(gl);
		}
		public void update(long time){
			for(updateIterator = 0; updateIterator < treeCount; ++updateIterator)
				trees[updateIterator].update(time);
		}
		
		class Tree{
			private float height;
			private float x;
			
			public Tree( float x, float h){
				this.x = x;
				height = h;
			}
			public void draw(GL10 gl){
				Shapes.drawSquare(gl, x, 3 + height * .375f, .1f, height * .375f, 0, .35f, 0, 1);
				Shapes.drawSquare(gl, x, 3 + height * .25f, .15f, height * .25f, 0, .35f, 0, 1);
//				Shapes.drawSquare(gl, x, 3 + height * .375f, .1f, height * .375f, 0, .35f, 0, 1);
//				Shapes.drawSquare(gl, x, 3 + height * .375f, .15f, height * .125f, 0, .35f, 0, 1);
				Shapes.drawSquare(gl, x, 3 + height * .875f, .0325f, height * .125f, 0, .35f, 0, 1);
			}
			public void update(long time){
				
			}
		}
	}
}
